﻿using MediatR;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Domain.Purchase_sales;
using SheepCultivation.Common.Domain.PurchaseSales;
using SheepCultivation.Common.Domain.SheepBasicInformation;
using SheepCultivation.Common.Domain.Week3;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace SheepCultivation.API.AddliCation.PurchaseSales
{
    public class SheepSaleCreateHandler : IRequestHandler<SheepSaleCreateCommon, Result>
    {
        public readonly IBaseRepository<SheepSale> SheepSaleRepository;
        public SheepSaleCreateHandler(IBaseRepository<SheepSale> sheepSaleRepository)
        {
            SheepSaleRepository = sheepSaleRepository;
        }
        public async Task<Result> Handle(SheepSaleCreateCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var list = new SheepSale()
                {
                    BreedingSheepArchiveId = request.BreedingSheepArchiveId,
                    SoldPrice=request.SoldPrice,
                    Pricing=request.Pricing,
                    Discount = request.Discount,
                    Rank = request.Rank,
                    SheepbreedId = request.SheepbreedId,
                    Sex = request.Sex,
                    SheepTypesId=request.SheepTypesId,
                    ReproductiveState=request.ReproductiveState,
                    BuildingId = request.BuildingId,
                    ColumnsId = request.ColumnsId,
                    BirthDate=request.BirthDate,
                    BirthWeight=request.BirthWeight,
                    Weight=request.Weight,
                    FatherNumber=request.FatherNumber,
                    MotherNumber=request.MotherNumber,
                    MonthAge=request.MonthAge,
                    SaleDate=request.SaleDate,
                    DepotId=request.DepotId,
                    ClientId=request.ClientId,
                    Addresses=request.Addresses,
                    SalesmanId=request.SalesmanId,
                    Numberes=request.Numberes,
                    DepartmentId=request.DepartmentId,
                    SerialNumber=request.SerialNumber,
                };
                SheepSaleRepository.Add(list);
                res.Code = (int)CommonEnumCode.success;
                res.Msg = "羊只销售新增成功";
             }
            catch (Exception)
            {

                res.Msg = "羊只销售新增失败";
                
            }
            return res;
            }
    }
}
